package com.isunland.managesystem.adapter;

import android.content.Context;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.isunland.managesystem.R;
import com.isunland.managesystem.entity.StaffscoreTypeContent.ScoreTypeContent;
import java.util.List;

/**
 * Created by wu on 2016/5/12.
 */
public class ScoreContentListAdapter extends ArrayAdapter<ScoreTypeContent> {

  /**
   * ViewHolder class for layout.<br />
   * <br />
   * Auto-created on 2016-04-25 10:39:46 by Android Layout Finder
   * (http://www.buzzingandroid.com/tools/android-layout-finder)
   */
  private static class ViewHolder {
    public final LinearLayout rootView;
    public final LinearLayout llHolderOneSimpleList;
    public final TextView tvTitleOneSimpleList;
    public final TextView tvContentOneSimpleList;
    public final LinearLayout llHolderTwoSimpleList;
    public final TextView tvTitleTwoSimpleList;
    public final TextView tvContentTwoSimpleList;
    public final LinearLayout llHolderThreeSimpleList;
    public final TextView tvTitleThreeSimpleList;
    public final TextView tvContentThreeSimpleList;
    public final LinearLayout llHolderFourSimpleList;
    public final TextView tvTitleFourSimpleList;
    public final TextView tvContentFourSimpleList;
    public final LinearLayout llHolderFiveSimpleList;
    public final TextView tvTitleFiveSimpleList;
    public final TextView tvContentFiveSimpleList;

    private ViewHolder(LinearLayout rootView, LinearLayout llHolderOneSimpleList,
        TextView tvTitleOneSimpleList, TextView tvContentOneSimpleList,
        LinearLayout llHolderTwoSimpleList, TextView tvTitleTwoSimpleList,
        TextView tvContentTwoSimpleList, LinearLayout llHolderThreeSimpleList,
        TextView tvTitleThreeSimpleList, TextView tvContentThreeSimpleList,
        LinearLayout llHolderFourSimpleList, TextView tvTitleFourSimpleList,
        TextView tvContentFourSimpleList, LinearLayout llHolderFiveSimpleList,
        TextView tvTitleFiveSimpleList, TextView tvContentFiveSimpleList) {
      this.rootView = rootView;
      this.llHolderOneSimpleList = llHolderOneSimpleList;
      this.tvTitleOneSimpleList = tvTitleOneSimpleList;
      this.tvContentOneSimpleList = tvContentOneSimpleList;
      this.llHolderTwoSimpleList = llHolderTwoSimpleList;
      this.tvTitleTwoSimpleList = tvTitleTwoSimpleList;
      this.tvContentTwoSimpleList = tvContentTwoSimpleList;
      this.llHolderThreeSimpleList = llHolderThreeSimpleList;
      this.tvTitleThreeSimpleList = tvTitleThreeSimpleList;
      this.tvContentThreeSimpleList = tvContentThreeSimpleList;
      this.llHolderFourSimpleList = llHolderFourSimpleList;
      this.tvTitleFourSimpleList = tvTitleFourSimpleList;
      this.tvContentFourSimpleList = tvContentFourSimpleList;
      this.llHolderFiveSimpleList = llHolderFiveSimpleList;
      this.tvTitleFiveSimpleList = tvTitleFiveSimpleList;
      this.tvContentFiveSimpleList = tvContentFiveSimpleList;
    }

    public static ViewHolder create(LinearLayout rootView) {
      LinearLayout llHolderOneSimpleList =
          (LinearLayout) rootView.findViewById(R.id.ll_holderOne_simpleList);
      TextView tvTitleOneSimpleList = (TextView) rootView.findViewById(R.id.tv_titleOne_simpleList);
      TextView tvContentOneSimpleList =
          (TextView) rootView.findViewById(R.id.tv_contentOne_simpleList);
      LinearLayout llHolderTwoSimpleList =
          (LinearLayout) rootView.findViewById(R.id.ll_holderTwo_simpleList);
      TextView tvTitleTwoSimpleList = (TextView) rootView.findViewById(R.id.tv_titleTwo_simpleList);
      TextView tvContentTwoSimpleList =
          (TextView) rootView.findViewById(R.id.tv_contentTwo_simpleList);
      LinearLayout llHolderThreeSimpleList =
          (LinearLayout) rootView.findViewById(R.id.ll_holderThree_simpleList);
      TextView tvTitleThreeSimpleList =
          (TextView) rootView.findViewById(R.id.tv_titleThree_simpleList);
      TextView tvContentThreeSimpleList =
          (TextView) rootView.findViewById(R.id.tv_contentThree_simpleList);
      LinearLayout llHolderFourSimpleList =
          (LinearLayout) rootView.findViewById(R.id.ll_holderFour_simpleList);
      TextView tvTitleFourSimpleList =
          (TextView) rootView.findViewById(R.id.tv_titleFour_simpleList);
      TextView tvContentFourSimpleList =
          (TextView) rootView.findViewById(R.id.tv_contentFour_simpleList);
      LinearLayout llHolderFiveSimpleList =
          (LinearLayout) rootView.findViewById(R.id.ll_holderFive_simpleList);
      TextView tvTitleFiveSimpleList =
          (TextView) rootView.findViewById(R.id.tv_titleFive_simpleList);
      TextView tvContentFiveSimpleList =
          (TextView) rootView.findViewById(R.id.tv_contentFive_simpleList);
      return new ViewHolder(rootView, llHolderOneSimpleList, tvTitleOneSimpleList,
          tvContentOneSimpleList, llHolderTwoSimpleList, tvTitleTwoSimpleList,
          tvContentTwoSimpleList, llHolderThreeSimpleList, tvTitleThreeSimpleList,
          tvContentThreeSimpleList, llHolderFourSimpleList, tvTitleFourSimpleList,
          tvContentFourSimpleList, llHolderFiveSimpleList, tvTitleFiveSimpleList,
          tvContentFiveSimpleList);
    }
  }

  @Override public View getView(int position, View convertView, ViewGroup parent) {
    final ViewHolder vh;
    if (convertView == null) {
      View view = mInflater.inflate(R.layout.adapter_score_content, parent, false);
      vh = ViewHolder.create((LinearLayout) view);
      view.setTag(vh);
    } else {
      vh = (ViewHolder) convertView.getTag();
    }

    ScoreTypeContent content = getItem(position);

    //最大分值限定
    if (!TextUtils.isEmpty(content.getMaxLimitScore())) {
      vh.llHolderOneSimpleList.setVisibility(View.VISIBLE);
      vh.tvTitleOneSimpleList.setText(R.string.maxFillScore);
      vh.tvContentOneSimpleList.setText(content.getMaxLimitScore());
    } else {
      vh.llHolderOneSimpleList.setVisibility(View.GONE);
    }

    //最小分值限定
    if (!TextUtils.isEmpty(content.getMinLimitScore())) {
      vh.llHolderFourSimpleList.setVisibility(View.VISIBLE);
      vh.tvTitleFourSimpleList.setText(R.string.minFillScore);
      vh.tvContentFourSimpleList.setText(content.getMinLimitScore());
    } else {
      vh.llHolderFourSimpleList.setVisibility(View.GONE);
    }

    //分值系数
    if (!TextUtils.isEmpty(content.getScoreFactor())) {
      vh.llHolderFiveSimpleList.setVisibility(View.VISIBLE);
      vh.tvTitleFiveSimpleList.setText(R.string.scoreFactore);
      vh.tvContentFiveSimpleList.setText(content.getScoreFactor());
    } else {
      vh.llHolderFiveSimpleList.setVisibility(View.GONE);
    }
    // 奖惩类别
    vh.tvTitleTwoSimpleList.setText(R.string.scoreType_colon);
    vh.tvContentTwoSimpleList.setText(content.getRewardKindName());
    vh.tvContentTwoSimpleList.setTextColor(
        getContext().getResources().getColor(R.color.blue_click));

    //奖惩内容
    vh.tvTitleThreeSimpleList.setText(R.string.scoreContent);
    if (!TextUtils.isEmpty(content.getRewardContent())) {
      vh.tvContentThreeSimpleList.setText(content.getRewardContent());
    } else {
      vh.tvContentThreeSimpleList.setText("");
    }
    return vh.rootView;
  }

  private LayoutInflater mInflater;

  public ScoreContentListAdapter(Context context, List<ScoreTypeContent> objects) {
    super(context, 0, objects);
    this.mInflater = LayoutInflater.from(context);
  }

  public ScoreContentListAdapter(Context context, ScoreTypeContent[] objects) {
    super(context, 0, objects);
    this.mInflater = LayoutInflater.from(context);
  }
}
